<!-- 运单货物跟踪 当前位置 -->
<template>
  <div v-if="visible"
       class="waybill-location-wrap">
    <!-- {{ location.waybillEquipmentStatus || '--' }}-->
    {{ currentLocation || '--' }}
  </div>
</template>

<script>
import transport from "@/api/modules/transport";
// import { mapActions, mapState } from "vuex";
export default {
  name: 'WaybillLocation',
  props: {
    value: {
      type: Object,
      default: () => { }
    }
  },
  data () {
    return {
      currentLocation: ''
    }
  },
  computed: {
    /* 
     * 1：当 el-table 某列使用了 fixed 属性，el-table 会为了实现 fixed 渲染多次
     * 2：通过判断其父级组件（$parent，即 table 实例）的 fixed 属性为 undefined，来辨别真正显示在 table 内的该组件实例（非 fixed 的那个）
     * 3：所以 fixed = undefined 的组件，才执行后续的方法
    */
    visible () {
      return !this.$parent.$parent.fixed;
    },
  },
  mounted () {
    if (this.visible) {
      this.waybillTrack(this.value)
    }
    // this.waybillTrack(this.value)
  },
  methods: {
    // ...mapActions({
    //   waybillTrack: "location/waybillTrack"
    // }),
    async waybillTrack (row) {
      if (row.status === 40 || row.status === 50) return
      if (row.deviceCode) {
        // if (item.status != 40 || item.status != 50) {
        let response = await transport.getByDevCode(row.deviceCode, 1);
        if (response) {
          // item.equipmentStatus = `${updateDeviceCode?.data?.lithiumValue} | ${updateDeviceCode?.data?.status}`
          // if (
          //   response?.data?.lithiumValue &&
          //   response?.data?.status
          // ) {
          //   // commit(GOODS_TRACK_TYPES.WAYBILL_EQUIPMENT_STATUS, `${response?.data?.lithiumValue} | ${response?.data?.status}`)
          //   this.equipmentStatus = `${response?.data?.lithiumValue} | ${response?.data?.status}`;
          // }
          if (response?.data?.positionAddress) {
            // commit(GOODS_TRACK_TYPES.WAYBILL_CURRENT_LOCATION, response?.data?.positionAddress)
            this.currentLocation = response?.data?.positionAddress;
          }
        }
        // }
      }
    },
  }
}
</script>

<style>
</style>